home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / batchut / task11.zip / TASK11.ASM < prev    next >
Assembly Source File  |  1987-11-08  |  6KB  |  151 lines

  1.         name    TASK
  2.         page    80,130
  3.         title   TASK -- Accepts keyboard input in a .BAT file.
  4.         subttl  _______  Written by:  Davy Crockett  _______
  5.  
  6. ;       ---------------------------------
  7. ;       :   Davy Crockett Productions   :
  8. ;       :   5807 Cherrywood Lane, 104   :
  9. ;       :   Greenbelt, Maryland 20770   :
  10. ;       ---------------------------------
  11.  
  12. ; Modification History              Date Written: 10 September 1985
  13.  
  14. ; 01/20/86 : changed from ASK to TASK.                  Ver 1.1
  15.  
  16. ; TASK -- This little program accepts a single keystroke
  17. ;         and sets the error level on return to DOS.
  18.  
  19. ; Execute with:  TASK <prompt> <$valid-responses>
  20. ;
  21. ; Both <prompt> and <$valid-responses> are optional.
  22. ; If a prompt is not supplied, TASK simply waits for a key
  23. ; to be pressed and returns an ErrorLevel equal to the ASCII
  24. ; code of the key pressed.
  25. ;
  26. ; The valid responses must begin with a "$".
  27. ; If a string of valid responses is not supplied,
  28. ; TASK will accept any key pressed and return the code.
  29. ; All input is converted to upper case before it is
  30. ; checked against the validation table.
  31.  
  32. cr      equ     0DH             ; carriage return
  33. lf      equ     0AH             ; line feed
  34. eol     equ     '$'             ; ascii eol sign
  35.  
  36. prompt  equ     80H             ; buffer for command tail
  37.  
  38. cseg    segment para public 'CODE'
  39.  
  40.         assume  cs:cseg,ds:cseg
  41.  
  42.         org     100H            ; start .COM at 100H
  43.  
  44. task    proc    far
  45.  
  46. ;       Check for a Prompt String
  47.  
  48.         mov     si,prompt       ; point to command tail
  49.         lodsb                   ; pick up the first character
  50.         test    al,al           ; is there anything there?
  51.         jz      accept_input    ; no, jump to get input
  52.         xor     ah,ah           ; yes, find the end
  53.         add     ax,prompt+1     ;  of the prompt line
  54.         mov     di,ax           ; move pointer to proper reg
  55.         mov     al,eol          ; load EOL indicator
  56.         stosb                   ; mark the end of prompt
  57.         mov     al,0            ; end of tail marker
  58.         stosb                   ; assure end of tail marker
  59.  
  60.         mov     si,prompt+2     ; point to start
  61. scan_loop:
  62.         lodsb                   ; pick up the byte
  63.         cmp     al,eol          ; found a dollar sign?
  64.         jnz     scan_loop       ; no, continue scan
  65.         lodsb                   ; pick up the next byte
  66.         cmp     al,0            ; end of command tail?
  67.         jz      end_scan        ; yes, skip move
  68.         mov     di,offset vtable ; point to destination
  69. move_loop:
  70.         call    to_upper        ; convert to upper case
  71.         stosb                   ; store this byte
  72.         lodsb                   ;  and pick up the next
  73.         cmp     al,eol          ; end of validation string?
  74.         jnz     move_loop       ; no, continue moving
  75.  
  76. end_scan:
  77.         mov     dx,prompt+2     ; point to the beginning
  78.         mov     ah,09H          ; load function code
  79.         int     21H             ; display the prompt
  80.  
  81. ;       Accept a single keystroke from the user
  82.  
  83. accept_input:
  84.         mov     ah,08H          ; load function code
  85.         int     21H             ; accept a keystroke
  86.         call    to_upper        ; convert to upper case
  87.         cmp     al,0            ; function key pressed?
  88.         jnz     validation      ; no, go to validate
  89.         mov     ah,08H          ; strip out extended
  90.         int     21H             ;  key
  91.         jmp     razz            ;   and razz the user
  92.  
  93. ;       Scan for Verification Table & Validate
  94.  
  95. validation:
  96.         mov     si,offset vtable ; point to validation string
  97.         cmp     byte ptr[si],0  ; validations supplied?
  98.         jz      input_accepted  ; no, accept this byte
  99. valid_loop:
  100.         cmp     byte ptr[si],0  ; end of string?
  101.         jz      razz            ; yes, invalid key
  102.         cmp     al,byte ptr[si] ; valid byte?
  103.         jz      input_accepted  ; yes, jump to process
  104.         inc     si              ; bump the pointer
  105.         jmp     valid_loop      ; no, continue validation
  106.  
  107. ;       Invalid input, Razz the user
  108.  
  109. razz:
  110.         mov     ah,02H          ; load function code
  111.         mov     dl,07H          ;  & beep code
  112.         int     21H             ; beep the user
  113.         jmp     accept_input    ; return for proper input
  114.  
  115. ;       Return keystroke as Error Level
  116.  
  117. input_accepted:
  118.         push    ax              ; save the keystroke
  119.         mov     dl,al           ; move input to DL reg
  120.         mov     ah,02H          ; load function code
  121.         int     21H             ; display keystroke
  122.         mov     dl,cr           ; display CR
  123.         mov     ah,02H          ;
  124.         int     21H             ;
  125.         mov     dl,lf           ; display LF
  126.         mov     ah,02H          ;
  127.         int     21H             ;
  128.         pop     ax              ; retrieve keystroke
  129.         mov     ah,4CH          ; set error code & return
  130.         int     21H             ;
  131.  
  132. vtable  dw      128 dup(0)      ; validation table storage
  133.  
  134. task    endp
  135.  
  136. ;       Convert lower case to UPPER CASE
  137.  
  138. to_upper        proc    near
  139.         cmp     al,'a'          ; smaller than little "a"?
  140.         jb      pass_char       ; yes, skip conversion
  141.         cmp     al,'z'          ; bigger than little "z"?
  142.         ja      pass_char       ; yes, skip conversion
  143.         sub     al,20H          ; no, convert
  144. pass_char:
  145.         ret                     ; return to main
  146. to_upper        endp
  147.  
  148. cseg    ends
  149.  
  150.         end     task
  151.